home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / type.h < prev    next >
C/C++ Source or Header  |  1996-01-30  |  9KB  |  324 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9. /* type.h - combined header file for types and templates for use
  10.  * by generator and interpreter 
  11.  */
  12.  
  13. /* Type codes (stored in first word of type template) */
  14.  
  15. #define TT_I_RANGE             0
  16. #define TT_L_RANGE             1
  17. #define TT_FL_RANGE             2
  18. #define TT_ENUM                 3
  19. #define TT_E_RANGE             4
  20. #define TT_FX_RANGE             5
  21. #define TT_ACCESS             6
  22. #define TT_U_ARRAY             7
  23. #define TT_C_ARRAY             8
  24. #define TT_S_ARRAY             9
  25. #define TT_D_ARRAY             10
  26. #define TT_RECORD             11
  27. #define TT_U_RECORD             12
  28. #define TT_V_RECORD             13
  29. #define TT_C_RECORD             14
  30. #define TT_D_RECORD             15
  31. #define TT_TASK                 16
  32. #define TT_SUBPROG             17
  33.  
  34.  
  35. /* Type templates represent Ada types at interpretor run time */
  36.  
  37. /* The first two fields (ints) of all type templates contain the type code */
  38. /* (from the above) list in the first word, and the length of the object in */
  39. /* the second word. The following are for accessing these two fields */
  40.  
  41. #define TYPE(ptr)          (*ptr)
  42. #define SIZE(ptr)          (*(ptr + 1))
  43.  
  44.  
  45. /* Integer range template */
  46.  
  47. struct tt_i_range {
  48.    int           ttype;
  49.    int           object_size;
  50.    int           ilow;
  51.    int           ihigh;
  52. };
  53.  
  54.  
  55. #ifdef LONG_INT
  56. /* Long integer range template */
  57. /* Note that long integers are not supported by this version */
  58. struct tt_l_range {
  59.    int           ttype;
  60.    int           object_size;
  61.    long           llow;
  62.    long           lhigh;
  63. };
  64. #endif
  65.  
  66.  
  67. /* Enumeration (sub)type template */
  68. /* This is used for both tt_enum and tt_e_range types in SETL version.
  69.  * fields ebase and eoff are base and offset for base type for tt_e_range
  70.  * case and are not defined (zero) for tt_enum case.
  71.  * For tt_enum case, literal values immediately follow, one for each
  72.  * case in the range. Each literal value consists of word giving length
  73.  * of value followed by that number of further words (with one character
  74.  * per word) giving the characters of the literal.
  75.  */
  76. struct tt_e_range {
  77.    int           ttype;
  78.    int           object_size;
  79.    int           elow;
  80.    int           ehigh;
  81.    int           ebase;        /* only in enumeration subtype */
  82.    int           eoff;        /* only in enumeration subtype */
  83. };
  84.  
  85.  
  86. /* Floating point template */
  87.  
  88. struct tt_fl_range {
  89.    int           ttype;
  90.    int           object_size;
  91.    double       fllow;
  92.    double       flhigh;
  93. };
  94.  
  95.  
  96. /* Fixed point template */
  97.  
  98. struct tt_fx_range {
  99.    int           ttype;
  100.    int           object_size;
  101.    int           small_exp_2;
  102.    int           small_exp_5;
  103.    long           fxlow;
  104.    long           fxhigh;
  105. };
  106.  
  107.  
  108. /* Access template */
  109.  
  110. struct tt_access {
  111.    int           ttype;
  112.    int           object_size;
  113.    int           master_task;
  114.    int           master_bfp;
  115.    int           collection_size;
  116.    int           collection_avail;
  117. };
  118.  
  119.  
  120. /* Simple array template */
  121.  
  122. struct tt_s_array {
  123.    int           ttype;
  124.    int           object_size;
  125.    int           component_size;
  126.    int           index_size;
  127.    int           salow;
  128.    int           sahigh;
  129. };
  130.  
  131.  
  132. /* Unconstrained or constrained array template */
  133.  
  134. struct tt_array {
  135.    int           ttype;
  136.    int           object_size;
  137.    int           dim;
  138.    int           component_base;
  139.    int           component_offset;
  140.    int           index1_base;
  141.    int           index1_offset;
  142. };
  143.  
  144.  
  145. /* Template for unconstrained record */
  146.  
  147. struct tt_u_record {
  148.    int           ttype;
  149.    int           object_size;
  150.    int           repr_size; 
  151.    int           nb_field_u;
  152.    int           nb_discr_u;
  153.    int           nb_fixed_u;
  154.    int           variant;
  155.    int           first_case;
  156.    /* field table follows here */
  157. };
  158.  
  159.  
  160. /* Template for constrained record */
  161.  
  162. struct tt_c_record {
  163.    int           ttype;
  164.    int           object_size;
  165.    int           repr_size; 
  166.    int           cbase;
  167.    int           coff;
  168.    int           nb_discr_c;
  169.    /* discriminant values follow here */
  170. };
  171.  
  172.  
  173. /* Template for simple record */
  174.  
  175. struct tt_record {
  176.    int           ttype;
  177.    int           object_size;
  178.    int           repr_size; 
  179.    int           nb_field;
  180.    /* field table follows here */
  181. };
  182.  
  183.  
  184. /* Template for types depending on discriminants */
  185.  
  186. struct tt_d_type {
  187.    int           ttype;
  188.    int           object_size;
  189.    int           repr_size; 
  190.    int           dbase;
  191.    int           doff;
  192.    int           nb_discr_d;
  193.    /* entries for discriminants follow here */
  194. };
  195.  
  196.  
  197. /* Task type template */
  198.  
  199. struct tt_task {
  200.    int           ttype;
  201.    int           object_size;
  202.    int           collection_size;
  203.    int           collection_avail;
  204.    int           priority;
  205.    int           body_base;
  206.    int           body_off;
  207.    int           nb_entries;
  208.    int           nb_families;
  209. #ifdef MONITOR
  210.    char               task_name[120];
  211.    char               task_file[120];
  212. #endif
  213.    /* entry table follows here */
  214. };
  215.  
  216.  
  217. /* Subprogram template */
  218.  
  219. struct tt_subprog {
  220.    int           ttype;
  221.    int           object_size;
  222.    int           cs;
  223.    int           relay_slot;
  224.    /* relay set entries follow here */
  225. };
  226.  
  227. /* Look at pointers with type changed to pointer to type template */
  228. /* Typical usage is XXX(ptr)->fieldname, where XXX is template name */
  229.  
  230. #define FL_RANGE(ptr)          ((struct tt_fl_range *)ptr)
  231. #define FX_RANGE(ptr)          ((struct tt_fx_range *)ptr)
  232. #define E_RANGE(ptr)          ((struct tt_e_range  *)ptr)
  233. #define I_RANGE(ptr)          ((struct tt_i_range  *)ptr)
  234. #define L_RANGE(ptr)          ((struct tt_l_range  *)ptr)
  235. #define ACCESS(ptr)          ((struct tt_access   *)ptr)
  236. #define S_ARRAY(ptr)          ((struct tt_s_array  *)ptr)
  237. #define ARRAY(ptr)          ((struct tt_array       *)ptr)
  238. #define TASK(ptr)          ((struct tt_task       *)ptr)
  239. #define SUBPROG(ptr)          ((struct tt_subprog  *)ptr)
  240. #define RECORD(ptr)          ((struct tt_record   *)ptr)
  241. #define D_TYPE(ptr)          ((struct tt_d_type   *)ptr)
  242. #define U_RECORD(ptr)          ((struct tt_u_record *)ptr)
  243. #define C_RECORD(ptr)          ((struct tt_c_record *)ptr)
  244.  
  245.  
  246. /* Size of templates in words (int's), not including variable fields */
  247.  
  248. #define WORDS_FL_RANGE          (sizeof(struct tt_fl_range) / sizeof(int))
  249. #define WORDS_FX_RANGE          (sizeof(struct tt_fx_range) / sizeof(int))
  250. #define WORDS_E_RANGE          (sizeof(struct tt_e_range)  / sizeof(int))
  251. #define WORDS_I_RANGE          (sizeof(struct tt_i_range)  / sizeof(int))
  252. #define WORDS_L_RANGE          (sizeof(struct tt_l_range)  / sizeof(int))
  253. #define WORDS_ACCESS          (sizeof(struct tt_access)      / sizeof(int))
  254. #define WORDS_S_ARRAY          (sizeof(struct tt_s_array)  / sizeof(int))
  255. #define WORDS_ARRAY          (sizeof(struct tt_array)      / sizeof(int))
  256. #define WORDS_TASK          (sizeof(struct tt_task)      / sizeof(int))
  257. #define WORDS_SUBPROG          (sizeof(struct tt_subprog)  / sizeof(int))
  258. #define WORDS_RECORD          (sizeof(struct tt_record)      / sizeof(int))
  259. #define WORDS_D_TYPE          (sizeof(struct tt_d_type)      / sizeof(int))
  260. #define WORDS_U_RECORD          (sizeof(struct tt_u_record) / sizeof(int))
  261. #define WORDS_C_RECORD          (sizeof(struct tt_c_record) / sizeof(int))
  262.  
  263. /* FLOAT corresonds to SETL float.Since C uses doubles, we use double
  264.  * conversion.
  265.  */
  266. #define FLOAT(x) ((double) (x))
  267. #ifdef OLD
  268. -- old GEN codes
  269. #define TT_I_RANGE                      1
  270. #define TT_F_RANGE                      2
  271. #define TT_ENUM                         3
  272. #define TT_E_RANGE                      4
  273. #define TT_FIXED                        5
  274. #define TT_ACCESS                       6
  275. #define TT_U_ARRAY                      7
  276. #define TT_C_ARRAY                      8
  277. #define TT_S_ARRAY                      9
  278. #define TT_D_ARRAY                     10
  279. #define TT_RECORD                      11
  280. #define TT_U_RECORD                    12
  281. #define TT_V_RECORD                    13
  282. #define TT_C_RECORD                    14
  283. #define TT_D_RECORD                    15
  284. #define TT_TASK                        16
  285. #define TT_SUBPROG                     17
  286. #endif
  287. #ifdef GEN
  288. /* TT_I_RANGE_L is introduced in first C version for long case (4 bytes)*/
  289.  
  290. /* TT_OBJECT_SIZE is offset in words from start of template to tt_object fiel.d
  291.  * This is needed in generating code for evaluting object_size of templates
  292.  * at run-time (cf type.c).
  293.  */
  294. #define TT_OBJECT_SIZE 1
  295.  
  296. /*S+ fields in enumeration (sub)type */
  297. /* In the C version, TT_E_RANGE_HIGH depends on the length of the enumeration
  298.  * type and immediately followed TT_E_RANGE_LOW.
  299.  */
  300.  
  301. /* The SETL table of the corresponding literals is represented in C
  302.  * as two vectors.The first has one entry for each literal giving the
  303.  * the length of the literal. This vector is followed the values of
  304.  * the literals. To find the position of the i-th literal we add together
  305.  * the lengths of the literals with index less than i.
  306.  */
  307.  
  308.  
  309. /*S+ fields in fixed point type */
  310. /* TBSL: for now assume, only 4 byte case, for VAX */
  311. /* The SETL definitions are misleasing in that ..range_low+1 is used
  312.  * for second word of multi-word case, etc.
  313.  */
  314.  
  315.  
  316. #endif
  317.  
  318.  
  319. /*
  320.  * TYPE_OFF gives the offset (in int's) of a field in a template
  321.  * (This is an example of C at its worst!)
  322.  */
  323. #define WORD_OFF(str, fld)   ( ((int)&(((struct str *)0)->fld)) / sizeof(int))
  324.